﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OCR.SystemThread
{
    class RecoveryDiskThread
    {
        public static bool RecoveryDiskThread_Flowrec = false;
        public static Thread RecoveryDiskFlow_Thread = null;


        public static bool RecoveryDiskThread_Pause = false;
        public static void CheckDiskSpace_Thread()
        {
            RecoveryDiskThread_Pause = true;
            RecoveryDiskThread_Flowrec = true;
            RecoveryDiskFlow_Thread = new Thread(DiskSpaceThreadFlow);
            RecoveryDiskFlow_Thread.IsBackground = true;
            RecoveryDiskFlow_Thread.Start();
        }

        private static void DiskSpaceThreadFlow()
        {
            while (RecoveryDiskThread_Flowrec)
            {
                if (!RecoveryDiskThread_Pause)
                {
                    Thread.Sleep(5000);
                    long temp_Total = DiskSpaceThread.GetHardDiskSpace(DiskSpaceThread.rootPath);
                    long temp_Remaining = DiskSpaceThread.GetHardDiskFreeSpace(DiskSpaceThread.rootPath);
                    float temp_Total_GB = temp_Total / DiskSpaceThread.GB;
                    float temp_Remaining_GB = temp_Remaining / DiskSpaceThread.GB;
                    Console.WriteLine("剩余比:{0}", temp_Remaining_GB / temp_Total_GB);

                    if (temp_Remaining_GB / temp_Total_GB >= 0.20f)
                    {
                        RecoveryDiskThread_Pause = true;
                        DiskSpaceThread.DiskSpaceThread_Pause = false;
                    }
                }

            }

        }
    }
}
